<template>
  <div class="page page-login">
    <div class="box-wrapper">
      <div class="box-main-wrapper">
        <div class="box box-login">
          <h2>找回密码</h2>
          <el-form class="login-form" ref="form" :model="form" :rules="rules">
            <el-form-item prop="email">
              <div class="icon-wrapper user">
                <svg-icon icon-class="user" />
              </div>
              <el-input
                v-model="form.email"
                autoComplete="off"
                placeholder="邮箱地址"
              />
            </el-form-item>
            <el-button
              class="btn-login"
              :loading="loading"
              type="primary"
              @click="submitForm('form')"
              >发送邮件</el-button
            >
            <p class="tips"><router-link to="/reset-password">重设密码</router-link>&nbsp;&nbsp;<router-link to="/login">登录</router-link></p>
          </el-form>
        </div>
      </div>
    </div>
    <footer-simple />
  </div>
</template>
<script>
import FooterSimple from "@/components/FooterSimple";

export default {
  name: "findPassword",
  components: { FooterSimple },
  data() {
    return {
      loading: false,
      form: {
        email: ""
      },
      rules: {
        email: [
          {
            required: true,
            trigger: "blur",
            type: "email",
            message: "请输入正确的邮箱地址。"
          }
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.loading = true;
          /*this.$store
            .dispatch('LoginByUsername', this.form)
            .then(() => {
              console.log('route');
              this.loading = false;
              this.$router.push({ path: '/' });
            })
            .catch(() => {
              this.loading = false;
            });*/
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    }
  }
};
</script>
<style scoped rel="stylesheet/scss" lang="scss">
.login-form {
  .tips {
    padding-top: 15px;
  }
}
</style>
